﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using FTchina;

public partial class UI_GetDinnerTableByPcountArea : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        string title = FTchina.basic.SafeRequest(Request["title"]);
        string type = FTchina.basic.SafeRequest(Request["type"]);
        string ChkId = FTchina.basic.SafeRequest(Request["ChkId"]);
        string ChkValueField = FTchina.basic.SafeRequest(Request["ChkValueField"]);
        string pcount = FTchina.basic.SafeRequest(Request["pcount"]);
        string area = FTchina.basic.SafeRequest(Request["area"]);
        string action = FTchina.basic.SafeRequest(Request["action"]);
        if (action == "OnlyList")
        {//只获取餐厅名称列表
            Response.Write(GetDinnerUseableList(ChkId, ChkValueField));

        }
        else
        {
            // FTchina.basic.Log(title + type + ChkValueField + ChkId + pcount);
            Response.Write(GetDinnerUseableList(title, type, ChkId, ChkValueField, pcount, area));

        }
    }


    /// <summary>
    /// 只获取餐厅名称
    /// </summary>
    /// <param name="ChkId"></param>
    /// <param name="ChkValueField"></param>
    /// <returns></returns>
    private string GetDinnerUseableList(string ChkId, string ChkValueField)
    {
        DataTable dt = shujuku.GetDataTable("select * from DinnerTableList  order by AreaName desc,pcount desc, DiningTableName desc ");
        string tmp = string.Empty;
        string chkbox = @"<label  title='header=[{0}] body=[容纳{2}人]'> <input type='checkbox' value='{3}{0}-{4}' id='{1}{5}'  name='{1}'   />{3}{0}   ({2}人)<label>";
         double x = dt.Rows.Count;
        double cloums = 4;
        double rows = Math.Ceiling(x / cloums);
        double num = 0;

        tmp += "<table width='100%' height='100%' valign='top' align='left'  cellpadding=0  border='1' cellspacing='0'  style='border-collapse: collapse;'  bordercolor='#cccccc'>";

        
        for (int i = 0; i < rows; i++)
        {
            tmp += "<tr  >";
            for (int j = 0; j < cloums; j++)
            {
                num = i * cloums + j;
                if (num >= x) { continue; }
                tmp += "<td  >" + string.Format(chkbox, dt.Rows[Convert.ToInt32(num)][ChkValueField].ToString(), ChkId, dt.Rows[Convert.ToInt32(num)]["pcount"], dt.Rows[Convert.ToInt32(num)]["AreaName"], dt.Rows[Convert.ToInt32(num)]["id"], dt.Rows[Convert.ToInt32(num)]["id"]) + "</td>";

            }
            tmp += "</tr>";
        }

        tmp += "</table>";
        return tmp;
    }


    /// <summary>
    /// 前台页面直接调用获取可预订资源
    /// </summary>
    /// <param name="title"></param>
    /// <param name="type"></param>
    /// <param name="ChkId"></param>
    /// <param name="ChkValueField"></param>
    /// <param name="pcount">按照人数进行过滤</param>
    /// <returns></returns>
    public String GetDinnerUseableList(string title, string type, string ChkId, string ChkValueField, string pcount, string area)
    {
         DataTable dt = shujuku.GetDataTable("select * from DinnerTableList where " + type + "customerid='' and pcount>=" + pcount + " and  areaname like '%" + area + "%' order by AreaName desc,pcount desc, DiningTableName desc ");
        string tmp = string.Empty;
        string chkbox = @"<label  title='header=[{0}] body=[容纳{2}人]'> <input type='checkbox' value='{3}{0}-{4}' id='{1}{5}'  name='{1}'   />{3}{0}   ({2}人)<label>";
        string DateInput = "   到店时间<input type='text' id='txbdate{0}' name='txbdate{0}'    /><div class='timer' id='timer" + type + "' >速选：" + GetTimeLableByType(type) + "</div>";
        double x = dt.Rows.Count;
        double cloums = 4;
        double rows = Math.Ceiling(x / cloums);
        double num = 0;

        tmp += "<table width='100%' height='100%' valign='top' align='left'  cellpadding=0  border='1' cellspacing='0'  style='border-collapse: collapse;'  bordercolor='#cccccc'>";

        //if (x > 0)
        //{
        //    tmp += "<tr><td colspan='" + cloums + "' align='left'><b>" + title + "<b>" + string.Format(DateInput, ChkId) + "</td></tr>";
        //}
        for (int i = 0; i < rows; i++)
        {
            tmp += "<tr  >";
            for (int j = 0; j < cloums; j++)
            {
                num = i * cloums + j;
                if (num >= x) { continue; }
                tmp += "<td  >" + string.Format(chkbox, dt.Rows[Convert.ToInt32(num)][ChkValueField].ToString(), ChkId, dt.Rows[Convert.ToInt32(num)]["pcount"], dt.Rows[Convert.ToInt32(num)]["AreaName"], dt.Rows[Convert.ToInt32(num)]["id"], dt.Rows[Convert.ToInt32(num)]["id"]) + "</td>";

            }
            tmp += "</tr>";
        }

        tmp += "</table>";
        return tmp;
    }

    /// <summary>
    /// 根据时间类型获取时间标签
    /// </summary>
    /// <param name="type"></param>
    /// <returns></returns>
    private String GetTimeLableByType(string type)
    {
        string tmp = string.Empty;
        switch (type)
        {
            case "zao":
                tmp = GetTimeLable(6, 9);
                break;
            case "zhong":
                tmp = GetTimeLable(11, 14);
                break;
            case "wan":
                tmp = GetTimeLable(17, 20);
                break;
            default:
                tmp = GetTimeLable(6, 22);
                break;
        }

        return tmp;

      

    }

    /// <summary>
    /// 获取指定时间范围内的格式标签
    /// </summary>
    /// <param name="start"></param>
    /// <param name="end"></param>
    /// <returns></returns>
    private String GetTimeLable(int start, int end)
    {
        string format = "<label>{0}</label>&nbsp;";
        string tmp = string.Empty;
        for (int i = start; i <= end; i++)
        {
            tmp += string.Format(format, i.ToString().PadLeft(2, '0') + ":00");
            tmp += string.Format(format, i.ToString().PadLeft(2, '0') + ":30");
        }
        return tmp;
    }
}